<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Kra8\Snowflake\HasSnowflakePrimary;
use SMartins\PassportMultiauth\HasMultiAuthApiTokens;

class Wechat extends Authenticatable
{
    use Notifiable,HasMultiAuthApiTokens,HasSnowflakePrimary;
    protected $fillable = [
        'name',
        'password',
        'phone',
        'open_id',
        'avatar_url',
        'gender',
        'session_key',
        'hobby'
    ];
    protected $hidden = [
        'password',
        'remember_token'
    ];
    public function findForPassport($username) {
        return $this->where('open_id', $username)->first();
    }
    public function getStatisticalAttribute(){
        return MemberStatistical::firstOrCreate([
            'member_id'=>$this->id,
            'platform'=>'WECHAT'
        ]);
    }
    public function getWalletAttribute(){
        return Wallet::firstOrCreate([
            'member_id'=>$this->id,
            'channel'=>'WECHAT'
        ]);
    }
    public function wallet(){
        $wallet = Wallet::firstOrCreate([
            'member_id'=>$this->id,
            'channel'=>'WECHAT'
        ]);
        return $wallet;
    }
}